package com.wholesale.config;

import com.wholesale.c3p0.C3p0Plugin;
import com.wholesale.model.Company;
import com.wholesale.plugin.activerecord.ActiveRecordPlugin;
import com.wholesale.plugin.activerecord.CaseInsensitiveContainerFactory;
import com.wholesale.plugin.activerecord.dialect.Sqlite3Dialect;

public class ProjectConfig {

    private ProjectConfig() {

    }

    public static void config() {
        String driverClass = "org.sqlite.JDBC";
        String jdbcUrl = "jdbc:sqlite:wholesale.db";

        C3p0Plugin cp = new C3p0Plugin(jdbcUrl, "", "");
        cp.setDriverClass(driverClass);

        ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);

        arp.setDialect(new Sqlite3Dialect());

        arp.addMapping("COMPANY", Company.class);
        arp.setContainerFactory(new CaseInsensitiveContainerFactory(true));

        cp.start();
        arp.start();

    }
}
